<?php

class Store
{ 
    private $Name; 
    private $Location; 
    private $Phone; 
    private $UserID;
    private $UploadPath;
    private $db;
            
    function __construct($userID=null, $name=null, $location=null, $phone=null, $imageName=FALSE){
        //set data
      
      $this->setData($userID, $name, $location, $phone, $imageName);
        //connect db
      
       $this->connectDB();
       
     //insert to database
      if($userID==null) {
          
       }
       else{
                    
            $this->initStore();
           
       }
      
    }
    private function toArray() 
    { 
        return (array) $this; 
		
    }
    private function setData($userID,$name,$location,$phone,$imageName){
        $this->Name=$name;
        $this->Location=$location;
        $this->Phone=$phone;
     // $this->UploadPath=$uploadPath;
        $this->UserID=$userID;
       if($imageName!=false){
        include 'imageClass.php';
        $img = new imgUploader();
        $this->UploadPath=  $img->UploadPath($imageName);
    }
 else {
        $this->UploadPath=null;
    }
    }
    private function connectDB(){
        
      try {
          require_once'database.php';
     $db_config_file="db_config.php";
     $this->db=new database($db_config_file);
}   
       catch (Exception $ex) {
       $ex->getMessage(); 
}
  
    }
    public  function initStore(){
 
    $sql="INSERT INTO store (storeName,address,stPhone,stImage,us_ID)
     VALUES ('$this->Name','$this->Location','$this->Phone','$this->UploadPath','$this->UserID')";

     if (!mysql_query($sql))
{
      throw new Exception("error:failed to create Store.");
}   else {
    
    return true;
}
}
//////////////////////////////link 3shan yroo7 llstore 
    private function displayStore($row){
echo "<div class=show >";
echo "<img src='".$row['stImage']."' width=100 height=100 />";
echo "<br/>";
  
  echo "<br>";
  echo "</div>";

}



///////////////////////// query msh 8alt awy
function getStore($id){
$sql="select * from store where storeID=$id";
$result=mysql_query($sql);
if($result){
while($row = mysql_fetch_array($result))
  {
   displayStore($row);
  }
  }
  else{
return false;  

  }
}
/////////////// tom much info to retrieve
function getStores(){
$sql="select * from store";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result))
  {
    $this->displayStore($row);
  }
}
 

//////////////////////////////////////

////////////////////////////////////////
	
} 

?>

